package com.twu.biblioteca;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class BibliotecaApp {

    private static MenuOptions menuOptions;
    private static WelcomeMessage welcomeMessage;
    private static CentralController centralController;
    private static Bookcase bookcase;
    private static MovieLibrary movieLibrary;
    public static User legalUser;

    public static void main(String[] args) {
        initSystem();
        welcomeMessage.showMessage();
        while (true) {
            menuOptions.showMenu();
            display(centralController.returnResponse(getUserInput()));
            goOn();
            continue;
        }
    }

    private static void display(String result) {
        System.out.println(result);
    }

    public static void initSystem() {
        menuOptions = new MenuOptions();
        welcomeMessage = new WelcomeMessage();
        centralController = new CentralController();
        bookcase = new Bookcase();
        movieLibrary = new MovieLibrary();
        UserList.init();
        legalUser = null;
    }

    private static void goOn() {
        System.out.println("Press Enter to continue or Input \"exit\" to exit system...");
        String input = getUserInput();
        if (input.equals("exit")) {
            System.exit(0);
        }
    }

    public static String getUserInput() {
        BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in));
        try {
            return userInput.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "Input Error!";
    }

    public static Bookcase getBookcase() {
        return bookcase;
    }

    public static MovieLibrary getMovieLibrary() {
        return movieLibrary;
    }
}
